package com.ruoyi.personnel.controller;
import com.ruoyi.Outsider.domain.Outsider;
import com.ruoyi.Outsider.service.IOutsiderService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.personnel.uploadUtils.FileLoadedtoLocalhost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

@RestController
public class UploadController extends BaseController {
    @Autowired
    IOutsiderService outsiderService;

    @Anonymous
    @PostMapping("/wechat/upload")
    public R uploadWxUserInfo(@RequestParam("file")MultipartFile file){
        FileLoadedtoLocalhost.fileLoadedtoLocalhost(file);
        if (FileLoadedtoLocalhost.fileLoadedtoLocalhost(file)){
            return R.ok("上传成功");
        }
        return null;

    }
    @Anonymous
    @PostMapping("/wechat/faceVerify")
    public R wxFaceVerify(@RequestParam("name") String name,
                          @RequestParam("phone") String phone,
                          @RequestParam("document_type") String document_type,
                          @RequestParam("number") String number,
                          @RequestParam("gender") String gender,
                          @RequestParam("faceImage") String faceImage,
                          @RequestParam("reason") String reason,
                          @RequestParam("begin_Time") Date begin_Time,
                          @RequestParam("end_Time") Date end_Time
                          ){
        Outsider outsider=new Outsider();
        String faceImgUrl = faceImage.replace("http://tmp/", "/profile/upload/");
        outsider.setName(name);
        outsider.setPermit(2L);
        outsider.setPhone(phone);
        outsider.setDocumentType(Long.parseLong(document_type));
        outsider.setNumber(number);
        outsider.setGender(Long.parseLong(gender));
        outsider.setFaceImg(faceImgUrl);
        outsider.setReason(reason);
        outsider.setBeginTime(begin_Time);
        outsider.setEndTime(end_Time);

        Date now = new Date();
        outsider.setCreateTime(now);
        outsider.setUpdateTime(now);
        outsiderService.insertOutsider(outsider);
        return R.ok( "上传成功");

    }
    @Anonymous
    @PostMapping("/wechat/getVerifyStatus")
    public R getVerifyStatus(@RequestParam(required = false,value = "phone") String phone){
        System.out.println(phone);
        return R.ok(outsiderService.selectOutsiderByPhone(phone));
    }
}
